package com.lepu.app.usercenter.util;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;

import com.app.application.MyApplication;
import com.app.utils.Const;
import com.app.utils.LoginUtil;
import com.app.utils.Setting;
import com.app.utils.Utils;
import com.core.lib.core.ApiClient;
import com.core.lib.core.AsyncRequest;
import com.core.lib.utils.main.AppManager;
import com.core.lib.utils.main.UIHelper;
import com.core.lib.utils.main.UtilityBase;
import com.core.lib.utils.secure.EncodeMD5;
import com.lepu.pasm.R;

@SuppressLint("DefaultLocale")
public class UserCenterUtil {

    public static boolean sampleMethod(Context context,
                                       AsyncRequest asyncRequest, String requestFlag) {
        boolean flag = false;

        return flag;
    }

    /*
     * 登录
     */
    public static boolean login(Context context, AsyncRequest asyncRequest,
                                String requestFlag, String userContent, String pwdContent) {

        boolean flag = false;

        if (TextUtils.isEmpty(userContent) || userContent.length() != 11) {
            UIHelper.showToast(context, R.string.usercenter_user_msg);
            return flag;
        }

        if (TextUtils.isEmpty(pwdContent) || pwdContent.length() < 6
                || pwdContent.length() > 20) {
            UIHelper.showToast(context, R.string.usercenter_pwd_msg);
            return flag;
        }

        flag = true;

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("LoginID", userContent);
            params.put("Password", EncodeMD5.getMd5(pwdContent));

            params.put("DeviceSN", AppManager.getDeviceUniqueId(context));
            params.put("DeviceModel", AppManager.getDeviceModel(context));
            params.put("OSVersion", AppManager.getDeviceSdkVersion(context));

            params.put("BaiduUserID", MyApplication.getInstance().mBaiduUserId);
            params.put("BaiduChannelID", MyApplication.getInstance().mBaiduChannelId);
            params.put("GeTuiCID", MyApplication.getInstance().mGeTuiChannelId);

            params.put("BranchID", Setting.getBranchID(context));
            params.put("IOSDeviceToken", "");
            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getLoginUrl(), map, null, asyncRequest,
                requestFlag, true);
        
      //保存密码
        LoginUtil.savePassword(context, pwdContent);

        return flag;
    }

    /*
     * 注册
     */
    public static boolean register(Context context, AsyncRequest asyncRequest,
                                   String requestFlag, boolean questionRegister, String userContent,
                                   String codeContent, String pwdContent, String pwdContent2,String nickName,
                                   String question1, String answer1, String question2, String answer2,int IsPromotion) {

        boolean flag = false;

        // 密保注册
        if (questionRegister) {
            String question1_toast = context
                    .getString(R.string.usercenter_question_msg1);
            if (question1.equals(question1_toast)) {
                UIHelper.showToast(context, question1_toast);
                return flag;
            }

            if (TextUtils.isEmpty(answer1)) {
                UIHelper.showToast(context, R.string.usercenter_answer_1);
                return flag;
            }

            // 2
            String question2_toast = context
                    .getString(R.string.usercenter_question_msg2);
            if (question2.equals(question2_toast)) {
                UIHelper.showToast(context, question2_toast);
                return flag;
            }

            if (TextUtils.isEmpty(answer2)) {
                UIHelper.showToast(context, R.string.usercenter_answer_2);
                return flag;
            }
        }

        if (TextUtils.isEmpty(userContent) || userContent.length() != 11) {
            UIHelper.showToast(context, R.string.usercenter_user_msg);
            return flag;
        }

        if (TextUtils.isEmpty(codeContent)) {
            UIHelper.showToast(context, R.string.usercenter_code_msg);
            return flag;
        }

        if (TextUtils.isEmpty(pwdContent) || pwdContent.length() < 6
                || pwdContent.length() > 20) {
            UIHelper.showToast(context, R.string.usercenter_pwd_msg);
            return flag;
        }

        if (TextUtils.isEmpty(pwdContent2) || !pwdContent.equals(pwdContent2)) {
            UIHelper.showToast(context, R.string.usercenter_pwd_msg2);
            return flag;
        }
        
        if (TextUtils.isEmpty(nickName)) {
            UIHelper.showToast(context, "昵称不能为空，请输入您的昵称");
            return flag;
        }
        
        if(nickName.length() < 1 || nickName.length() > 14)
        {
        	UIHelper.showToast(context, "请输入昵称1~14个字符");
        	return flag;
        }
        
        if(nickName.equals(userContent))
        {
        	UIHelper.showToast(context, "昵称不能使用手机号，请重新设置");
            return flag;
        }

        flag = true;

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("LoginID", userContent);
            params.put("Password", EncodeMD5.getMd5(pwdContent));
            params.put("CAPTCHA", codeContent); // 验证码

            // 密保问题
            if (questionRegister) {
                params.put("SecurityQuestion1", question1);
                params.put("SecurityAnswer1", EncodeMD5.getMd5(answer1));
                params.put("SecurityQuestion2", question2);
                params.put("SecurityAnswer2", EncodeMD5.getMd5(answer2));
            }

            params.put("DeviceSN", AppManager.getDeviceUniqueId(context));
            params.put("DeviceModel", AppManager.getDeviceModel(context));
            params.put("OSVersion", AppManager.getDeviceSdkVersion(context));

            params.put("BaiduUserID", MyApplication.getInstance().mBaiduUserId);
            params.put("BaiduChannelID", MyApplication.getInstance().mBaiduChannelId);
            params.put("GeTuiCID", MyApplication.getInstance().mGeTuiChannelId);

            params.put("IOSDeviceToken", "");
            
            //new add
            params.put("NickName", nickName);
            
            String umengChannel = UtilityBase.getAppMetedata(context,
					"UMENG_CHANNEL");
			params.put("AppChannel",umengChannel);

			String ClientVersion = AppManager.getPackageInfo(context,
					context.getPackageName()).versionName;
			params.put("ClientVersion", ClientVersion);
			
			/**
			 * 是否促销 此参数是为了实现特殊的促销引导注册特殊增加积分 0-非促销 1-促销
			 */
			params.put("IsPromotion", IsPromotion);

            params.put("BranchID", Setting.getBranchID(context));
			
            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getRegisterUrl(), map, null, asyncRequest,
                requestFlag, true);
        
        //保存密码
        LoginUtil.savePassword(context, pwdContent);

        return flag;
    }
    
    /*
     * 获取注册验证码
     */
    public static boolean getRegisterCode(Context context,
                                          AsyncRequest asyncRequest, String requestFlag, String userContent) {

        boolean flag = false;

        if (TextUtils.isEmpty(userContent) || userContent.length() != 11) {
            UIHelper.showToast(context, R.string.usercenter_user_msg);
            return flag;
        }

        flag = true;

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("LoginID", userContent);
            
            params.put(Const.CODE_KEY, Utils.getCodeValue(userContent));
            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getRegisterCodeUrl(), map, null,
                asyncRequest, requestFlag, true);

        return flag;
    }
    
    /*
     * 获取绑定验证码
     */
    public static boolean getBondCode(Context context,
                                          AsyncRequest asyncRequest, String requestFlag, String userContent) {

        boolean flag = false;

        if (TextUtils.isEmpty(userContent) || userContent.length() != 11) {
            UIHelper.showToast(context, R.string.usercenter_user_msg);
            return flag;
        }

        flag = true;

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("LoginID", userContent);
            
            params.put(Const.CODE_KEY, Utils.getCodeValue(userContent));
            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getRegisterCodeUrl(), map, null,
                asyncRequest, requestFlag, false);

        return flag;
    }

    /*
     * 获取重置密码 验证码
     */
    public static boolean getResetPasswordCode(Context context,
                                               AsyncRequest asyncRequest, String requestFlag, String userContent) {

        boolean flag = false;

        if (TextUtils.isEmpty(userContent) || userContent.length() != 11) {
            UIHelper.showToast(context, R.string.usercenter_user_msg);
            return flag;
        }

        flag = true;

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("LoginID", userContent);
            
            params.put(Const.CODE_KEY, Utils.getCodeValue(userContent));
            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getResetPasswordCodeUrl(), map, null,
                asyncRequest, requestFlag, true);

        return flag;
    }

    /*
     * 获取 通过验证码 重置密码
     */
    public static boolean getResetPasswordByCode(Context context,
                                                 AsyncRequest asyncRequest, String requestFlag, String userContent,
                                                 String codeContent, String pwdContent, String pwdContent2) {

        boolean flag = false;

        if (TextUtils.isEmpty(userContent) || userContent.length() != 11) {
            UIHelper.showToast(context, R.string.usercenter_user_msg);
            return flag;
        }

        if (TextUtils.isEmpty(codeContent)) {
            UIHelper.showToast(context, R.string.usercenter_code_msg);
            return flag;
        }

        if (TextUtils.isEmpty(pwdContent) || pwdContent.length() < 6
                || pwdContent.length() > 20) {
            UIHelper.showToast(context, R.string.usercenter_pwd_msg);
            return flag;
        }

        if (TextUtils.isEmpty(pwdContent2) || !pwdContent.equals(pwdContent2)) {
            UIHelper.showToast(context, R.string.usercenter_pwd_msg2);
            return flag;
        }

        flag = true;

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("LoginID", userContent);
            params.put("CAPTCHA", codeContent);
            params.put("Password", EncodeMD5.getMd5(pwdContent));
            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getResetPasswordByCodeUrl(), map, null,
                asyncRequest, requestFlag, true);

        return flag;
    }

    /*
     * 获取密保问题
     */
    public static boolean getPwdQuestion(Context context,
                                         AsyncRequest asyncRequest, String requestFlag) {

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);
            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getPwdQuestionUrl(), map, null,
                asyncRequest, requestFlag, true);

        return true;
    }

    /*
     * 获取 通过手机获取密保问题
     */
    public static boolean getPwdQuestionByPhone(Context context,
                                                AsyncRequest asyncRequest, String requestFlag, String userContent) {

        boolean flag = false;

        if (TextUtils.isEmpty(userContent) || userContent.length() != 11) {
            UIHelper.showToast(context, R.string.usercenter_user_msg);
            return flag;
        }

        flag = true;

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("LoginID", userContent);
            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getPwdQuestionByPhoneUrl(), map, null,
                asyncRequest, requestFlag, true);

        return flag;
    }

    /*
     * 通过密保问题修改密码
     */
    public static boolean getResetPwdByPwdQuestion(Context context,
                                                   AsyncRequest asyncRequest, String requestFlag, String userContent,
                                                   String pwdContent, String pwdContent2, String question1,
                                                   String answer1, String question2, String answer2) {

        boolean flag = false;

        if (TextUtils.isEmpty(answer1)) {
            UIHelper.showToast(context, R.string.usercenter_answer_1);
            return flag;
        }

        if (TextUtils.isEmpty(answer2)) {
            UIHelper.showToast(context, R.string.usercenter_answer_2);
            return flag;
        }

        if (TextUtils.isEmpty(userContent) || userContent.length() != 11) {
            UIHelper.showToast(context, R.string.usercenter_user_msg);
            return flag;
        }

        if (TextUtils.isEmpty(pwdContent) || pwdContent.length() < 6
                || pwdContent.length() > 20) {
            UIHelper.showToast(context, R.string.usercenter_pwd_msg);
            return flag;
        }

        if (TextUtils.isEmpty(pwdContent2) || !pwdContent.equals(pwdContent2)) {
            UIHelper.showToast(context, R.string.usercenter_pwd_msg2);
            return flag;
        }

        flag = true;

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("LoginID", userContent);
            params.put("Password", EncodeMD5.getMd5(pwdContent));

            // 密保问题
            params.put("SecurityQuestion1", question1);
            params.put("SecurityAnswer1", EncodeMD5.getMd5(answer1));
            params.put("SecurityQuestion2", question2);
            params.put("SecurityAnswer2", EncodeMD5.getMd5(answer2));

            params.put("DeviceSN", AppManager.getDeviceUniqueId(context));
            params.put("DeviceModel", AppManager.getDeviceModel(context));
            params.put("OSVersion", AppManager.getDeviceSdkVersion(context));

            params.put("BaiduUserID", MyApplication.getInstance().mBaiduUserId);
            params.put("BaiduChannelID", MyApplication.getInstance().mBaiduChannelId);
            params.put("IOSDeviceToken", "");
            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getResetPwdByPwdQuestionUrl(), map, null,
                asyncRequest, requestFlag, false);

        return flag;
    }

    /*
     * 获取 更新密保问题
     */
    public static boolean getUpdateSecurityQuestion(Context context,
                                                    AsyncRequest asyncRequest, String requestFlag, String UserID,
                                                    String LoginToken, String question1, String answer1,
                                                    String question2, String answer2) {

        boolean flag = false;

        String question1_toast = context
                .getString(R.string.usercenter_question_msg1);
        if (question1.equals(question1_toast)) {
            UIHelper.showToast(context, question1_toast);
            return flag;
        }

        if (TextUtils.isEmpty(answer1)) {
            UIHelper.showToast(context, "请填写答案");
            return flag;
        }

        // 2
        String question2_toast = context
                .getString(R.string.usercenter_question_msg2);
        if (question2.equals(question2_toast)) {
            UIHelper.showToast(context, question2_toast);
            return flag;
        }

        if (TextUtils.isEmpty(answer2)) {
            UIHelper.showToast(context, "请填写答案");
            return flag;
        }

        flag = true;

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);
            params.put("UserID", UserID);
            params.put("LoginToken", LoginToken);
            params.put("CAPTCHA", "-1");

            params.put("SecurityQuestion1", question1);
            params.put("SecurityAnswer1", EncodeMD5.getMd5(answer1));
            params.put("SecurityQuestion2", question2);
            params.put("SecurityAnswer2", EncodeMD5.getMd5(answer2));

            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getUpdateSecurityQuestionUrl(), map, null,
                asyncRequest, requestFlag, true);

        return flag;
    }

    /*
     * 获取修改密码
     */
    public static boolean getModifyPwd(Context context,
                                       AsyncRequest asyncRequest, String requestFlag, String UserID,
                                       String LoginToken, String oldPwd, String pwdContent, String pwdContent2) {

        boolean flag = false;

        if (TextUtils.isEmpty(oldPwd) || oldPwd.length() < 6
                || oldPwd.length() > 20) {
            UIHelper.showToast(context, R.string.usercenter_pwd_msg);
            return flag;
        }

        if (TextUtils.isEmpty(pwdContent) || pwdContent.length() < 6
                || pwdContent.length() > 20) {
            UIHelper.showToast(context, R.string.usercenter_pwd_msg);
            return flag;
        }

        if (TextUtils.isEmpty(pwdContent2) || !pwdContent.equals(pwdContent2)) {
            UIHelper.showToast(context, R.string.usercenter_pwd_msg2);
            return flag;
        }

        flag = true;

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);
            params.put("UserID", UserID);
            params.put("LoginToken", LoginToken);

            params.put("CurrentPassword",
                    EncodeMD5.getMd5(oldPwd));
            params.put("NewPassword",
                    EncodeMD5.getMd5(pwdContent));
            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getModifyPwdUrl(), map, null, asyncRequest,
                requestFlag, true);

        return flag;
    }

    /*
     * 获取意见反馈
     */
    public static boolean getFeedback(Context context,
                                      AsyncRequest asyncRequest, String requestFlag, String UserID,
                                      String LoginToken, String content, String contact,String AdviceID) {

        boolean flag = false;

        if (TextUtils.isEmpty(content)) {
            UIHelper.showToast(context, "请您填写一些建议");
            return flag;
        }
        
        if(content.length() < 5 || content.length() > 400){
        	UIHelper.showToast(context, "请您输入5-400字");
        	return false;
        }

        //联系方式，服务端可空
//		if (TextUtils.isEmpty(concact)) {
//			UIHelper.showToast(context, "请您填写联系方式");
//			return flag;
//		}

        flag = true;

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("UserID", UserID);
            params.put("LoginToken", LoginToken);

            params.put("Content", content);
            params.put("ContactInfo", contact);
            
            params.put("AdviceID", AdviceID);
            
            params.put("DeviceSN", AppManager.getDeviceUniqueId(context));
            params.put("DeviceModel", AppManager.getDeviceModel(context));
            params.put("OSVersion", AppManager.getDeviceSdkVersion(context));
            
            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getFeedbackUrl(), map, null, asyncRequest,
                requestFlag, true);

        return flag;
    }

    /**
     * 举报用户
     *
     * @param asyncRequest
     * @param requestFlag
     * @param targetType
     * @param TargetID
     * @param contentType
     * @param remark
     */
    public static void useReport(AsyncRequest asyncRequest, String requestFlag,
                                 int targetType, String TargetID, int contentType, String remark,
                                 String TargetName) {
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);
            params.put("UserID", LoginUtil.getUserId());
            params.put("LoginToken", LoginUtil.getLoginToken());
            params.put("TargetType", targetType);
            params.put("TargetID", TargetID);
            params.put("ContentType", contentType);
            params.put("TargetName", TargetName);
            params.put("Remark", remark);
            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }
        ApiClient.http_post(Setting.useReportUrl(), map, null, asyncRequest,
                requestFlag, true, true);

    }
    
    //===================================第三方账户登录=================================
    /*
     * bond
     */
    public static boolean bond(Context context, AsyncRequest asyncRequest,
                                   String requestFlag, String userContent,
                                   String codeContent, String pwdContent, String pwdContent2) {

        boolean flag = false;

        if (TextUtils.isEmpty(userContent) || userContent.length() != 11) {
            UIHelper.showToast(context, R.string.usercenter_user_msg);
            return flag;
        }

        if (TextUtils.isEmpty(codeContent)) {
            UIHelper.showToast(context, R.string.usercenter_code_msg);
            return flag;
        }

        if (TextUtils.isEmpty(pwdContent) || pwdContent.length() < 6
                || pwdContent.length() > 20) {
            UIHelper.showToast(context, R.string.usercenter_pwd_msg);
            return flag;
        }

        if (TextUtils.isEmpty(pwdContent2) || !pwdContent.equals(pwdContent2)) {
            UIHelper.showToast(context, R.string.usercenter_pwd_msg2);
            return flag;
        }
        
        flag = true;

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);
            
            params.put("UserID", LoginUtil.getUserId());
            params.put("LoginToken", LoginUtil.getLoginToken());

            params.put("LoginID", userContent);
            params.put("Password", EncodeMD5.getMd5(pwdContent));
            params.put("CAPTCHA", codeContent); // 验证码

            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getBondUrl(), map, null, asyncRequest,
                requestFlag, true,true);

        return flag;
    }
    
    /*
     * 第三方用户登录
     */
    public static boolean thirdLogin(Context context, AsyncRequest asyncRequest,
                                   String requestFlag, String ThirdpartyAccount,
                                   int TATID, String TAAccessToken, String TAAccessTokenExpireTime) {

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);
            
            params.put("ThirdpartyAccount", ThirdpartyAccount);
            params.put("TATID", TATID);
            params.put("TAAccessToken", TAAccessToken);
            params.put("TAAccessTokenExpireTime", TAAccessTokenExpireTime);

            params.put("DeviceSN", AppManager.getDeviceUniqueId(context));
            params.put("DeviceModel", AppManager.getDeviceModel(context));
            params.put("OSVersion", AppManager.getDeviceSdkVersion(context));

            params.put("BaiduUserID", MyApplication.getInstance().mBaiduUserId);
            params.put("BaiduChannelID", MyApplication.getInstance().mBaiduChannelId);
            params.put("IOSDeviceToken", "");

            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getThirdpartyLogin(), map, null, asyncRequest,
                requestFlag, true);

        return true;
    }
    
    /*
     * 第三方用户登录 bond
     */
    public static boolean thirdpartyBind(Context context, AsyncRequest asyncRequest,
                                   String requestFlag,String NickName,String yaoQingCode, String ThirdpartyAccount,
                                   int TATID, String TAAccessToken, String TAAccessTokenExpireTime) {

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);
            
            params.put("NickName", NickName);
            params.put("ThirdpartyAccount", ThirdpartyAccount);
            params.put("TATID", TATID);
            params.put("TAAccessToken", TAAccessToken);
            params.put("TAAccessTokenExpireTime", TAAccessTokenExpireTime);

            params.put("DeviceSN", AppManager.getDeviceUniqueId(context));
            params.put("DeviceModel", AppManager.getDeviceModel(context));
            params.put("OSVersion", AppManager.getDeviceSdkVersion(context));

            params.put("BaiduUserID", MyApplication.getInstance().mBaiduUserId);
            params.put("BaiduChannelID", MyApplication.getInstance().mBaiduChannelId);
            params.put("IOSDeviceToken", "");
            
            params.put("InvitationCode", yaoQingCode);//test

            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post_main(Setting.getThirdpartyBind(), map, null, asyncRequest,
                requestFlag, true);

        return true;
    }

    /*
     * 获取通用验证码
     */
    public static boolean getCommonCode(Context context,
                                          AsyncRequest asyncRequest, String requestFlag, String userContent) {

        boolean flag = false;

        if (TextUtils.isEmpty(userContent) || userContent.length() != 11) {
            UIHelper.showToast(context, R.string.usercenter_user_msg);
            return flag;
        }

        flag = true;

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("LoginID", userContent);
            
            params.put(Const.CODE_KEY, Utils.getCodeValue(userContent));
            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getCommonCodeUrl(), map, null,
                asyncRequest, requestFlag, true);

        return flag;
    }

    /*
    * 获取修改手机号
    */
    public static boolean getUpdateLoginID(Context context,
                                        AsyncRequest asyncRequest, String requestFlag, String oldUserContent, String newUserContent,String codeContent) {

        boolean flag = false;

        if (TextUtils.isEmpty(newUserContent) || newUserContent.length() != 11) {
            UIHelper.showToast(context, R.string.usercenter_user_msg);
            return flag;
        }

        if (TextUtils.isEmpty(codeContent)) {
            UIHelper.showToast(context, R.string.usercenter_code_msg);
            return flag;
        }

        flag = true;

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("CAPTCHA", codeContent);
            params.put("OldLoginID", oldUserContent);
            params.put("LoginID", newUserContent);

            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }


        ApiClient.http_post(Setting.getUpdateLoginIDUrl(), map, null,
                asyncRequest, requestFlag, true);

        return flag;
    }

    public static void getTellPhone() {

        Map<String, Object> map = new HashMap<String, Object>();
        try {
            JSONObject params = new JSONObject();
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);
            params.put("DeviceSN", "android");

            map.put("ht", params);
        } catch (Exception e) {
            e.printStackTrace();
        }

        ApiClient.http_post(Setting.getTellPhoneUrl(), map, null, new AsyncRequest() {
                    @Override
                    public void RequestComplete(Object object, Object data) {
                        try {
                            JSONObject jsonObject = new JSONObject((String) data);
                            JSONObject obj1 = (JSONObject) jsonObject.get("Result");
                            JSONObject obj2 = obj1.getJSONObject("DetailInfo");

                            String phone = obj2.optString("PASM_phone", "");
                            Setting.TELL_PHONE = phone;
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void RequestError(Object o, int i, String s) {

                    }
                },
                "", false);
    }
}
